package com.heima.article.service.impl;

import com.heima.article.mapper.ApArticleMapper;
import com.heima.article.service.IArticleHomeService;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @projectName: heima-leadnews
 * @package: com.heima.article.service.impl
 * @className: ArticleHomeServiceImpl
 * @author: ZhouAo
 * @description: TODO
 * @date: 2022/6/12 18:29
 * @version: 1.0
 */
@Service
public class ArticleHomeServiceImpl implements IArticleHomeService {
    @Autowired
    private ApArticleMapper mapper;

    @Override
    public ResponseResult load(ArticleHomeDto dto, Integer i) {
        Integer size = dto.getSize();

        if (size == null || size == 0) {
            dto.setSize(10);
        }
        //时间设置
        if (dto.getMaxBehotTime()==null){
            dto.setMaxBehotTime(new Date());
        }
        if (dto.getMinBehotTime()==null){
            dto.setMinBehotTime(new Date());
        }

        return ResponseResult.okResult(mapper.loadArticleList(dto, i));
    }
}
